<template>
  <div>
    <el-table :data="items">
        <el-table-column prop="id" label="ID" width="230">
        </el-table-column>
        <el-table-column prop="name" label="用户名">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
      <template slot-scope="scope">
        <el-button type="text" size="small" @click="$router.push(`/admin_users/edit/${scope.row.id}`)">编辑</el-button>
        <el-button type="text" size="small" @click="remove(scope.row)">删除</el-button>
      </template>
    </el-table-column>
      </el-table>
      <el-pagination
        layout="prev, pager, next"
        :page-size="size"
        @current-change="current_change"
        :total="total">
      </el-pagination>
  </div>
</template>
<script>
export default {
  data(){
    return{
      items:[],
      total:0,
      size:0
    }
  },
  methods:{
    async fetch(){
      const res =await this.$http.get('admins')
      this.items=res.data.infos.list
      this.total=res.data.infos.total
      this.size=res.data.infos.size
    },
    async remove(row){
      this.$confirm(`此操作将永久删除"${row.name}", 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(async () => {
          const res =await this.$http.delete(`admin/${row.id}`)
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.fetch()
        })          
      },
    async current_change(page){
        console.log(page)
        const res =await this.$http.get(`/admins?pn=${page}`)
        this.items = res.data.infos.list
      },
  },
  created(){
    this.fetch()
  }
};
</script>

